#
# Boost.mk
#
# Boost distribution definitions.
#

#
# Variables.
#

#
# Define several variables associated with Boost.
#
BOOST = boost
BOOST_BASE = $(BOOST)_1_51_0
BOOST_DIST_FILE_NAME = $(BOOST_BASE).tar.gz
BOOST_DIST_FILE_PATH = $(DIST_DIR)/$(BOOST_DIST_FILE_NAME)
BOOST_URL = http://sourceforge.net/projects/boost/files/boost/1.51.0/boost_1_51_0.tar.gz/download

#
# Define the library files produced by Boost.
#
BOOST_BASE_LIBRARY_NAMES = program_options
BOOST_LIBRARIES = $(addprefix $(LIB_DIR)/libboost_,program_options.a $(call shared_library_name,program_options) $(if $(findstring Linux,$(OS)), $(call shared_library_name,program_options,1,51,0)))

#BOOST_LIBRARIES = $(addprefix $(LIB_DIR)/,libboost_chrono.a libboost_chrono.dylib libboost_date_time.a libboost_date_time.dylib libboost_exception.a libboost_filesystem.a libboost_filesystem.dylib libboost_graph.a libboost_graph.dylib libboost_iostreams.a libboost_iostreams.dylib libboost_math_c99.a libboost_math_c99.dylib libboost_math_c99f.a libboost_math_c99f.dylib libboost_math_c99l.a libboost_math_c99l.dylib libboost_math_tr1.a libboost_math_tr1.dylib libboost_math_tr1f.a libboost_math_tr1f.dylib libboost_math_tr1l.a libboost_math_tr1l.dylib libboost_prg_exec_monitor.a libboost_prg_exec_monitor.dylib libboost_program_options.a libboost_program_options.dylib libboost_python.a libboost_python.dylib libboost_random.a libboost_random.dylib libboost_regex.a libboost_regex.dylib libboost_serialization.a libboost_serialization.dylib libboost_signals.a libboost_signals.dylib libboost_system.a libboost_system.dylib libboost_test_exec_monitor.a libboost_thread.a libboost_thread.dylib libboost_unit_test_framework.a libboost_unit_test_framework.dylib libboost_wave.a libboost_wave.dylib libboost_wserialization.a libboost_wserialization.dylib)

#
# Directory Variables.
#

#
# BOOST_DIST_DIR
#
# Defines where the Boost distribution directory is located.
#
BOOST_DIST_DIR = $(DIST_DIR)/$(BOOST_BASE)

#
# BOOST_INC_DIR
#
# Defines where the Boost include directory is located.
#
BOOST_INC_DIR = $(INC_DIR)/$(BOOST)


#
# Canned recipes.
#

#
# Build Boost from source.
#
define build_boost
	@echo Building Boost...
	@cd $(BOOST_DIST_DIR);						       \
		./bootstrap.sh --prefix=$(DIST_PREFIX) --libdir=$(DIST_LIBDIR);\
		./b2 $(addprefix --with-,$(BOOST_BASE_LIBRARY_NAMES)) install;\
		cd ../../;						    \
		$(call touch_recursive,$(BOOST_INC_DIR));		    \
		$(call touch_recursive,$(LIB_DIR)/libboost*);
endef

#
# Targets.
#

#
# Define the .PHONY boost target.
#
.PHONY: $(BOOST)

#
# Download Boost distribution.
#
$(BOOST_DIST_FILE_PATH): | $(DIST_DIR)
	@echo Downloading $(BOOST_DIST_FILE_NAME)...
	@$(call download_file,$(BOOST_DIST_FILE_PATH),$(BOOST_URL))

#
# Extract Boost distribution.
#
$(BOOST_DIST_DIR): $(BOOST_DIST_FILE_PATH)
	@echo Extracting $(BOOST_DIST_FILE_NAME)...
	@$(call tar_extract,$(BOOST_DIST_FILE_PATH),$(DIST_DIR))
	@$(call touch_recursive,$(BOOST_DIST_DIR))

#
# Boost include directory.
#
$(BOOST_INC_DIR): $(BOOST_DIST_DIR)
	@$(build_boost)

#
# Boost library files.
#
$(BOOST_LIBRARIES): $(BOOST_DIST_DIR)
	@$(build_boost)

#
# Boost.
#
$(BOOST): $(BOOST_INC_DIR) $(BOOST_LIBRARIES)
